﻿--[[
   @brief    contact item node
   @author   perpu
   @version  1.0
   @date     2016-06-15
--]]

friend_vlist_node = {
    last_select_ = nil; --  本地代码用，记录上次选中的节点，用于快速取消选中
    last_hover_ = nil; --  本地代码用，记录上次hover的节点，用于快速取消hover

    update = function(nodetype, control_id, info)
        if nodetype == friend_vlist_model.NODE_TYPE_DISCUSSION_NODE or
           nodetype == friend_vlist_model.NODE_TYPE_GROUP_NODE then
            local group_info = info["group_info"];
            if group_info == nil then
                return;
            end;
            friend_vlist_model.virtual_node_id_to_group_info[control_id] = group_info;

            local title_id = ui_utility.get_ctrl_id_by_path(control_id, 'stack_title');
            local static_id = ui_utility.get_ctrl_id_by_path(control_id, 'stack_title\\Static_Friend_Name');
            
            local vip_param = comm_center.call_service('i_service_social_get_vip_value', {tgp_id =  group_info.friend_id});
            local vip_value = 0;
            if vip_param ~= nil and vip_param.judge_level ~= nil then
                vip_value = vip_param.judge_level;
            end

            local nick_name = group_info.new_name or "";
            if "" == nick_name then
                nick_name = group_info.name;
            end
            
            local nick_name_show_len = 9;

            if vip_value > 0 then
                local max_len = 9;
                if string.find(nick_name, "[^a-z0-9_]") == nil then
                    max_len = 17;
                end
                local is_need_cut_name = ui_utility.is_over_char_count(nick_name,max_len);
                nick_name_show_len = max_len;
                if is_need_cut_name then
                    nick_name_show_len = max_len-1;
                end
            else
                local max_len = 11;
                if string.find(nick_name, "[^a-z0-9_]") == nil then
                    max_len = 18;
                end
                local is_need_cut_name = ui_utility.is_over_char_count(nick_name, max_len);
                nick_name_show_len = max_len;
                if is_need_cut_name then
                    nick_name_show_len = max_len-1;
                end
            end

            local static_ptr = ui_utility.get_ctrl_ptr_by_path(control_id, 'stack_title\\Static_Friend_Name');
            if static_ptr ~= nil then
                local ui_str, str_holder = U8toCUIStrn(nick_name, nick_name_show_len, 1);
                static_ptr:SetText(ui_str);
            end

            local face_url = string.format("ONEIMAGE:client_social\\default_head.png|%s;Circle;null;", group_info.url);
            local head_id = ui_utility.get_ctrl_id_by_path(control_id, 'Button_Head_Image');
            ui_utility.setproperty_by_id(head_id, "Background", face_url)


            --游戏状态
            -- local in_param = {friend_id = group_info.friend_id};
            -- local out_param = comm_center.call_service('i_servie_lol_game_status_get_lol_gaming_status_string', in_param);
            -- if out_param ~= nil and out_param.status_str ~= nil then
            --     local online_txt_id = ui_utility.get_ctrl_id_by_path(control_id, 'OnLine_Container\\Static_Online');
            --     ui_utility.setproperty_by_id(online_txt_id,'Caption', out_param.status_str);
            --     ui_utility.setproperty_by_id(online_txt_id,'TextColor', friend_list_model.GAME_ONLINE_COLOR);
            -- end

            --在线状态
            local online_status = 0;
            local friend_info = group_info;
            if friend_info == nil then
                return;
            end
            local uilib = ui_utility:uilib();
            MainCommon.set_visible(uilib, MainCommon.get_child_id(uilib, control_id, "OnLine_Container\\Static_Online"), true);

            if friend_info.status ~= nil then
                online_status = friend_info.status;
            end

            -- test
            -- online_status = friend_list_model.TGP_GAMEING_STATUS;

            --是否灰显
            local hear_ptr =ui_utility.get_ctrl_ptr_by_id(head_id);
            if online_status == friend_list_model.TGP_OFFLINE_STATUS then
                hear_ptr:GrayBG(TRUE);
            else
                hear_ptr:GrayBG(FALSE);
            end;

            local game_status, game_id = friend_list_model.get_friend_status(friend_info.friend_id)
            -- test
            -- game_status = friend_list_model.TGP_GAMEING_STATUS;
            -- game_id = 1;

            ui_str, str_holder = U8toCUIStr("OnLine_Container\\Button_GameIcon");
            local game_icon_id = uilib:GetControlIDbyPath(ui_str, control_id);
            ui_utility.setproperty_by_id(game_icon_id, "Visible", "false");


            if online_status == friend_list_model.TGP_OFFLINE_STATUS then
                MainCommon.set_property(uilib, control_id, "OnLine_Container\\Static_Online", "Caption", "");
                MainCommon.set_visible(uilib, MainCommon.get_child_id(uilib, control_id, "OnLine_Container\\Static_Online"), false);
                MainCommon.set_property(uilib, control_id, "stack_title\\Static_Friend_Name", "TextColor", friend_list_model.OFFLINE_NAME_COLOR);

                friend_vlist_node.adjust_name_pos(false, title_id);
                friend_vlist_node.show_starve_join_game_btn(uilib, control_id, "false");
            else
                MainCommon.set_property(uilib, control_id, "stack_title\\Static_Friend_Name", "TextColor", friend_list_model.ONLINE_NAME_COLOR);
        
                ui_utility.setproperty_by_id(game_icon_id, "Visible", "true");
                MainCommon.set_visible(uilib, MainCommon.get_child_id(uilib, control_id, "OnLine_Container\\Static_Online"), true);
                friend_vlist_node.set_game_status_online_color(control_id, friend_list_model.GAME_ONLINE_COLOR);

                local game_status_str = nil;
                if game_id ~= 0 then
                    local game_info = banner_model.get_game_base_info(game_id);
                    if game_info ~= nil then
                        if game_id == GAME_ID.GAME_ID_LOL then
                            local in_param = {friend_id = friend_info.friend_id};
                            local out_param = comm_center.call_service('i_servie_lol_game_status_get_lol_gaming_status_string', in_param);
                            if out_param ~= nil and out_param.status_str ~= nil then
                                game_status_str = out_param.status_str;
                            else
                                game_status_str = LoadStr("SOCIAL_FRIEDN_LIST_GAMESTATE_LOL");
                            end
                        else
                            local temp_str = LoadStr("SOCIAL_FRIEDN_LIST_GAMESTATE_ONLINE");
                            game_status_str = string.format("%s%s", game_info.name, temp_str);
                        end
                    else
                        game_status_str = LoadStr("SOCIAL_FRIEDN_LIST_GAMESTATE_NEICE");
                    end
                end

                if friend_vlist_node.check_need_show_starve_join_game_btn(friend_info.friend_id, game_id) == true then
                    friend_vlist_node.show_starve_join_game_btn(uilib, control_id, "true");
                else
                    friend_vlist_node.show_starve_join_game_btn(uilib, control_id, "false");
                end

                local neice_str = LoadStr("SOCIAL_FRIEDN_LIST_GAMESTATE_NEICE");
                if game_status_str ~= nil then
                    friend_vlist_node.adjust_name_pos(true, title_id);
                    MainCommon.set_property(uilib, control_id, "OnLine_Container\\Static_Online", "Caption", game_status_str);
                    MainCommon.set_visible(uilib, MainCommon.get_child_id(uilib, control_id, "OnLine_Container\\Static_Online"), true);
                    friend_vlist_node.set_game_status_online_color(control_id, friend_list_model.GAME_ONLINE_COLOR);
                    if game_status_str == neice_str then
                        MainCommon.set_property(uilib, control_id, "OnLine_Container\\Static_Online", "Disable", "true");
                        MainCommon.set_property(uilib, control_id, "OnLine_Container\\Static_Online", "Transparent", "true");
                    else                        
                        MainCommon.set_property(uilib, control_id, "OnLine_Container\\Static_Online", "Disable", "false");
                        MainCommon.set_property(uilib, control_id, "OnLine_Container\\Static_Online", "Transparent", "false");
                    end
                else
                    friend_vlist_node.adjust_name_pos(false, title_id);
                    ui_utility.setproperty_by_id(game_icon_id, "Visible", "false");

                    MainCommon.set_property(uilib, control_id, "OnLine_Container\\Static_Online", "Caption", "");  
                    MainCommon.set_visible(uilib, MainCommon.get_child_id(uilib, control_id, "OnLine_Container\\Static_Online"), false);
                end
            end
            --选中态
            if friend_vlist_model.current_selected_group_id == group_info.friend_id then
                friend_vlist_node.set_selected_state(control_id, true);
            else
                friend_vlist_node.set_selected_state(control_id, false);
            end
        end;
    end;

    set_game_status_online_color = function(p_id, color)
        ui_utility.setproperty_by_path(p_id, "OnLine_Container\\Static_Online", "TextColor", color);
        ui_utility.setproperty_by_path(p_id, "OnLine_Container\\Static_Online", "TextColorHover", color);
        ui_utility.setproperty_by_path(p_id, "OnLine_Container\\Static_Online", "TextColorPressed", color);
        ui_utility.setproperty_by_path(p_id, "OnLine_Container\\Static_Online", "TextColorDisable", color)
    end;

    -- data = {}
    -- one_time = {key = "1", value="2"};
    -- table.insert(data, one_time);


    -- 加入游戏房间按钮事件
    --------------------------------------------------------------------------
    hover_on_join_game_room_btn = function(uilib, ctrl_id)
        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        friend_vlist_node.mouse_over_banner(uilib, p_id);
    end;
    leave_on_join_game_room_btn = function(uilib, ctrl_id)
        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        friend_vlist_node.mouse_leave_banner(uilib, p_id);

        -- ui_utility.setproperty_by_id(ctrl_id, "Background", "NONE;");
    end;
                    
    click_on_join_game_room_btn = function(uilib, ctrl_id)
        -- 数据上报
        local data = {};
        data["type"] = 2; --点击加入房间
        comm_center.call_service('i_service_increase_click_on_game_status_cnt', data); 

        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        friend_vlist_node.on_left_button_down(uilib, p_id);

        local state = friend_vlist_node.get_jh_state();
        base_utility.log("[friend_vlist_node] click_on_join_game_room_btn, state:"..tostring(state), true);
        -- 未安装 
        if  state == ierd_tgp.game_library.GAME_STATE_UNKNOWN then
            -- 打开饥荒游戏详情页
            comm_center.call_service('i_service_social_open_game_detail_web_page', {game_id = GAME_ID.GAME_ID_JH});
            return;
        end

        -- 查询是否购买
        local friend_info = friend_vlist_model.virtual_node_id_to_group_info[p_id];
        friend_vlist_node.query_is_me_have_game_jh(friend_info.friend_id);
    end;

    query_is_me_have_game_jh = function(friend_id)
        base_utility.log("[friend_vlist_node] query_is_me_have_game_jh", true);
        local lua_table = { }
        lua_table.dest = "0";
        lua_table.seq_num = "0";
        lua_table.callback_func = social_event.QUERY_GAME_BUY_INFO_FOR_JH;
        lua_table.data = {}
        lua_table.data.game_id = GAME_ID.GAME_ID_JH;
        lua_table.src = "0";
        
        friend_vlist_node.cur_query_jh_id = friend_id;

        local rail_host = base_utility.get_component_adapter(
                "IRailHost", "ierd_tgp.tgp_plugin.GetRailHostAdapter();");
        if rail_host ~= nil then
            local tpfui =
              base_utility.get_component_adapter("ITpf_ui",
                  "ierd_tgp.tpf_ui.GetTPFUI();");
                tpfui:AddLuaListener(ierd_tgp.tgp_plugin.QUERY_GAME_AUTHORITY_INFO, "friend_vlist_node.on_query_game_info");
            rail_host:QueryGameAuthorityInfo(base_utility.table_to_json(lua_table));
        end;
    end;

    on_query_game_info = function(event_id, json_str)
        local buy_info = base_utility.json_to_table(json_str);
        if buy_info.game_id == GAME_ID.GAME_ID_JH and friend_vlist_node.cur_query_jh_id ~= nil then
            local tpfui =
              base_utility.get_component_adapter("ITpf_ui",
                  "ierd_tgp.tpf_ui.GetTPFUI();");
            tpfui:RemoveLuaListener(ierd_tgp.tgp_plugin.QUERY_GAME_AUTHORITY_INFO, "friend_vlist_node.on_query_game_info");

            base_utility.log("[friend_vlist_node] on_query_game_info, json_str:"..json_str, true);
            friend_vlist_node.process_jh_query_result(buy_info, friend_vlist_node.cur_query_jh_id);
            friend_vlist_node.cur_query_jh_id = nil;
        end
    end;

    process_jh_query_result = function(buy_info, friend_id)
        if buy_info.result == 0 and buy_info.authority_info ~= nil 
            and buy_info.authority_info.state ~= nil then

            local state = friend_vlist_node.get_jh_state();

            if buy_info.authority_info.state == 0 then
                -- 未购买, 打开饥荒游戏详情页
                comm_center.call_service('i_service_social_open_game_detail_web_page', {game_id = GAME_ID.GAME_ID_JH});
            elseif buy_info.authority_info.state == 1 then
                -- 已经安装单可运行 已经购买, 进入房间
                if  state == ierd_tgp.game_library.GAME_STATE_NORMAL  or
                    state == ierd_tgp.game_library.GAME_STATE_RUNNING then
                    friend_vlist_node.try_to_join_jh_gam(friend_id);
                else
                    -- 已经安装单不可运行，则打开饥荒游戏助手页
                    local param = {};
                    param.module_id = GAME_ID.GAME_ID_JH;
                    event_center.send_event(banner_event.JUMP_MODULE_WEB, base_utility.table_to_json(param));
                end
            end
        else
            --查询失败的 tips
            friend_vlist_node.tips_join_game_error();
        end
    end;

    try_to_join_jh_gam = function(friend_id)
        local state = friend_vlist_node.get_jh_state();

        base_utility.log("[friend_vlist_node] try_to_join_jh_gam, state:"..tostring(state), true);
        if state == ierd_tgp.game_library.GAME_STATE_NORMAL  or 
               state == ierd_tgp.game_library.GAME_STATE_RUNNING then
            base_utility.log("[friend_vlist_node] join game sucess");
            local rail_host = base_utility.get_component_adapter(
                "IRailHost", "ierd_tgp.tgp_plugin.GetRailHostAdapter();");
            rail_host:JoinGame(GAME_ID.GAME_ID_JH, friend_id);
        else
            friend_vlist_node.tips_join_game_error();
        end       
    end;

    get_jh_state = function()
        local gl_adapter =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
        local gl_state = ierd_tgp.game_library.GameState:new_local();
        gl_adapter:get_game_state(GAME_ID.GAME_ID_JH, gl_state);
        return gl_state.iState;
    end;

    tips_join_game_error = function()
        base_utility.log("[friend_vlist_node] tips_join_game_error");
        local param = {
                position = 'center',--参数值: rbottom-右下角，center-居中
                title = LoadStr("SOCIAL_FRIEDN_LIST_JOINERR_TITLE"),
                width = 480,
                height = 230,
                titleIcon = "",
                icon = "",
                tipsIcon = poptips_icons.kError,
                descTitle = "",
                desc = LoadStr("SOCIAL_FRIEDN_LIST_JOINERR_DESC"),
                cancelBtn = {
                    visible = false,
                    text = LoadStr("SOCIAL_FRIEDN_LIST_JOINERR_CANCEL"),
                    handle = function()
                    end
                },
                okBtn = {
                    visible = true;
                    text = LoadStr("SOCIAL_FRIEDN_LIST_JOINERR_OK"),
                    handle = function()
                        poptips_control.close_tips();
                    end
                }
        };
        poptips_control.show_tips(param);
    end;

    check_need_show_starve_join_game_btn = function(friend_id, game_id)
        local b_ret = false;
        if game_id == GAME_ID.GAME_ID_JH then
            local tpfui =
                base_utility.get_component_adapter("ITpf_ui",
                    "ierd_tgp.tpf_ui.GetTPFUI();");
            local status, sub_status = friend_list_model.get_friend_game_detail_status(friend_id, game_id);
            local s1 = 0;
            local s2 = 0;
            if status ~= nil then
                s1 = tpfui:OperatorAnd(status, 0x08);
            end
            if sub_status ~= nil then
                s2 = tpfui:OperatorAnd(sub_status, 0x08);
            end
            if s1 > 0 or s2 > 0 then
                b_ret = true;
            end

            base_utility.log("[friend_vlist_node] check_need_show_starve_join_game_btn, s1:"..tostring(s1)..",s2:"..tostring(s2), true);
        end
        return b_ret;
        -- test
        -- return true;
    end;

    show_starve_join_game_btn = function(uilib, p_id, is_show)
        MainCommon.set_property(uilib, p_id, "Join_Game_Btn", "Visible", is_show);
    end;
    --------------------------------------------------------------------------

    adjust_name_pos = function(is_gaming, name_id)
        local name_ptr = ui_utility.get_ctrl_ptr_by_id(name_id);
        if name_ptr ~= nil then
            local rc = name_ptr:GetRectEx(FALSE,TRUE);
            h = rc.bottom - rc.top;
            if is_gaming == true then
                rc.top = 10;
                rc.bottom = rc.top + h;
            else
                rc.top = 18;
                rc.bottom = rc.top + h;
            end
            ui_utility.setproperty_by_id(name_id, "YOffset", tostring(rc.top));
            name_ptr:MoveEx(rc,TRUE);
        end
    end;

    restore_banner_bk = function()
        for k, v in pairs(friend_vlist_model.virtual_node_id_to_group_info) do
            if friend_vlist_model.current_hover_group_id ~= v.group_id then
                friend_vlist_node.set_normal_state(k);
            end
        end
    end;

    --以下是鼠标键盘消息处理
    mouse_over_on_game_online_button = function(uilib, ctrl_id)
        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        local pp_id = ui_utility.get_ctrl_parent_id(p_id);
        friend_vlist_node.mouse_over_banner(uilib, pp_id);
    end;

    on_right_button_up_on_game_online_button = function(uilib, ctrl_id, x, y)
        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        local ptr = ui_utility.get_ctrl_ptr_by_id(ctrl_id);
        local rc = ptr:GetRectEx(FALSE,TRUE);
        local r_p_x = rc.left + x;
        local r_p_y = rc.top + y;

        local pp_id = ui_utility.get_ctrl_parent_id(p_id);
        local ptr = ui_utility.get_ctrl_ptr_by_id(p_id);
        local rc = ptr:GetRectEx(FALSE,TRUE);
        local r_pp_x = rc.left + r_p_x;
        local r_pp_y = rc.top + r_p_y;

        friend_vlist_node.on_right_button_up(uilib, pp_id, r_pp_x, r_pp_y);
    end;

    click_on_game_online_button = function(uilib,  ctrl_id)
        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        local pp_id = ui_utility.get_ctrl_parent_id(p_id);

        friend_vlist_node.on_left_button_down(uilib, pp_id);

        local friend_info = friend_vlist_model.virtual_node_id_to_group_info[pp_id];
        if friend_info ~= nil then
            local game_status, game_id = friend_list_model.get_friend_status(friend_info.friend_id);
            if game_id ~= 0 then
                local out = comm_center.call_service('service_game_library_is_game_in_list', {game_id = game_id});
                if out.is_installed then
                    -- 游戏已在列表
                    local param = {};
                    param["type"] = "landing";
                    param["game_id"] = tostring(game_id);
                    web_utility.open_link_convert(base_utility.table_to_json(param));

                    local data = {};
                    data["type"] = 0; --好友列表
                    data["sub_type"] = 1; --助手
                    comm_center.call_service('i_service_increase_click_on_game_status_cnt', data);
                else
                    comm_center.call_service('i_service_social_open_game_detail_web_page', {game_id = game_id});

                    local data = {};
                    data["type"] = 0; -- 好友列表
                    data["sub_type"] = 0; --详情页
                    comm_center.call_service('i_service_increase_click_on_game_status_cnt', data);
                end
            end
        end
    end;

    mouse_over_banner = function(uilib, ctrl_id)
        if friend_vlist_node.last_hover_ then
            friend_vlist_node.set_normal_state(friend_vlist_node.last_hover_);
        end;
        friend_vlist_node.last_hover_ = ctrl_id;
        local g_info = friend_vlist_model.virtual_node_id_to_group_info[ctrl_id];
        if g_info ~= nil and g_info.group_id ~= friend_vlist_model.current_selected_group_id then
            friend_vlist_node.set_hover_state(ctrl_id);
        end
    end;

    mouse_leave_banner = function(uilib, ctrl_id)
        local g_info = friend_vlist_model.virtual_node_id_to_group_info[ctrl_id];
        if g_info ~= nil and g_info.group_id ~= friend_vlist_model.current_selected_group_id then
            friend_vlist_node.set_normal_state(ctrl_id);
        end
    end;

    on_left_button_down = function(uilib, ctrl_id)
        if friend_vlist_node.last_select_ then
            friend_vlist_node.set_selected_state(friend_vlist_node.last_select_, false);
        end;
        friend_vlist_node.last_select_ = ctrl_id;
        local g_info = friend_vlist_model.virtual_node_id_to_group_info[ctrl_id];
        friend_vlist_model.current_selected_group_id = g_info.friend_id;
        friend_vlist_node.set_selected_state(ctrl_id, true);
    end;

    on_right_button_down = function(uilib, ctrl_id)
    end;

    on_right_button_up = function(uilib, ctrl_id, x, y)
        local group_info = friend_vlist_model.virtual_node_id_to_group_info[ctrl_id];
        if group_info ~= nil then
            --friend_vlist_node.send_hide_group_tips_event(1);
            local pControl = ui_utility.get_ctrl_ptr_by_id(ctrl_id);
            local rc = pControl:GetRectEx(TRUE,TRUE);
            local param = {};
            param["friend_id"] = group_info.friend_id;
            param["x"] = rc.left + x;
            param["y"] = rc.top + y;
            event_center.send_event(group_event.SHOW_FRIEND_MENU,base_utility.table_to_json(param))

            local param = {};
            param["bShow"] = false;
            param["action"] = 1;
            event_center.send_event(group_event.SHOW_FRIEND_TIPS,base_utility.table_to_json(param));
        end
    end;

    mouse_db_click = function(uilib, ctrl_id)
        local selected = friend_vlist_node.last_select_
        local group_info = friend_vlist_model.virtual_node_id_to_group_info[selected];
        if group_info ~= nil then
            local table_param = {};
            local friends = {};
            local info = {};
            info.id = group_info.friend_id;
            info.is_new = false;
            info.time = friend_list_model.get_last_msg_time(info.id);
            table.insert(friends, info);
            table_param["friends"] = friends;

            event_center.send_event(group_event.SHOW_TALK_DIALOG,base_utility.table_to_json(table_param));
        end
    end;

    start_show_group_tip_timer = function()
        local tpfui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:AddInterval('friend_vlist_node.show_group_tip_timer_process', 300);
    end;

    stop_show_group_tip_timer = function()
        local tpfui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:RemoveInterval('friend_vlist_node.show_group_tip_timer_process');
    end;

    show_group_tip_timer_process = function()
        friend_vlist_node.stop_show_group_tip_timer();
        friend_vlist_node.send_show_group_tips_event();
    end;

    send_show_group_tips_event = function()
        local p_id = ui_utility.get_ctrl_parent_id(friend_vlist_node.current_hover_header_ctrl_id);
        if p_id == 0 then
            return;
        end
        local  group_info = friend_vlist_model.virtual_node_id_to_group_info[p_id];
        if group_info == nil then
            return;
        end

        local pControl = ui_utility.get_ctrl_ptr_by_id(friend_vlist_node.current_hover_header_ctrl_id);
        local rc = pControl:GetRectEx(TRUE,TRUE);
        local param = {};
        param["bShow"] = true;    
        param["friend_id"] = group_info.friend_id;
        local out = comm_center.call_service("i_service_mainframe_get_current_mode", {});
        if out.mode == 0 then
            param["x"] = rc.left + 2;
        else
            param["x"] = rc.left;
        end
        param["y"] = rc.top;
        event_center.send_event(group_event.SHOW_FRIEND_TIPS,base_utility.table_to_json(param));
    end;

    start_timer_hover_vip_tips = function()
        local tpfui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:AddInterval('friend_vlist_node.show_vip_tips', 300);
    end;

    stop_timer_hover_vip_tips = function()
        local tpfui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:RemoveInterval('friend_vlist_node.show_vip_tips');
    end;

    show_vip_tips = function()
        friend_vlist_node.stop_timer_hover_vip_tips();
        tqos_mgr.increase_hover_vip_tips_count();
    end;

    mouse_over_vip_imgage = function(uilib, ctrl_id)
        local p_id = ui_utility.get_ctrl_parent_id(ui_utility.get_ctrl_parent_id(ctrl_id));
        
        friend_vlist_node.set_hover_state(p_id);

        friend_vlist_node.start_timer_hover_vip_tips();
    end;

    mouse_leave_vip_imgage = function(uilib, ctrl_id)
        friend_vlist_node.stop_timer_hover_vip_tips();
    end;

    click_on_vip_flag = function(uilib, ctrl_id)
        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        local pp_id = ui_utility.get_ctrl_parent_id(p_id);
        local g_info = friend_vlist_model.virtual_node_id_to_group_info[pp_id];
        if g_info ~= nil then
            local param = {};
            param["type"] = "badge";
            param["sub_page"] = "BADGE_DETAIL";
            param["owner"] = tostring(login_model.im_login_infomation.friend_id);
            param["guest"] = tostring(g_info.friend_id);
            param["badge_type"] = 3;
            web_utility.open_link(base_utility.table_to_json(param));
        end
    end;

    mouse_over_imgage = function(uilib, ctrl_id)
        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        local g_info = friend_vlist_model.virtual_node_id_to_group_info[p_id];

        if friend_menu_view == nil or friend_menu_view.is_show() == false then
            friend_vlist_node.current_hover_header_ctrl_id = ctrl_id;
            friend_vlist_node.stop_show_group_tip_timer();
            friend_vlist_node.start_show_group_tip_timer();
        end
        
        friend_vlist_node.set_hover_state(p_id);
    end;

    mouse_leave_imgage = function(uilib, ctrl_id)
        base_utility.log("[friend_vlist_node] mouse_leave_group_imgage");
        friend_vlist_node.stop_show_group_tip_timer();

        if friend_menu_view == nil or friend_menu_view.is_show() == false then
            friend_vlist_node.send_hide_group_tips_event(0);
        end
    end;

    on_left_button_up_image = function(uilib, ctrl_id)
        base_utility.log("[friend_vlist_node] on_left_button_up_image");

        local p_id = ui_utility.get_ctrl_parent_id(ctrl_id);
        local g_info = friend_vlist_model.virtual_node_id_to_group_info[p_id];
        if g_info ~= nil then
--            local table_param = {};
--            local page_info = {};
--            page_info["id"] = GAME_ID.GAEM_ID_HOME_PAGE;
--            local url_str = "http://plat.tgp.qq.com/platform/profile/icenter.html?tgp_id=" .. g_info.friend_id .. "&from=social";
--            page_info["url"] = url_str;
--            table_param["page_info"] = page_info;
--            comm_center.call_service("i_service_open_page", table_param);
            local data = {type = "profile", tgp_id = g_info.friend_id, custom_param = "&from=social"};
            web_utility.open_link_convert(base_utility.table_to_json(data));
        end
    end;
    
    on_left_button_down_image = function(uilib, ctrl_id)
        base_utility.log("[friend_vlist_node] on_left_button_down_image");
        friend_vlist_node.send_hide_group_tips_event(1);
    end;

    on_right_button_down_image = function(uilib, ctrl_id, x, y)
        friend_vlist_node.stop_show_group_tip_timer();
        friend_vlist_node.send_hide_group_tips_event(1);
    end;

    on_right_button_up_image = function(uilib, ctrl_id, x, y)
        friend_vlist_node.stop_show_group_tip_timer();
        friend_vlist_node.send_hide_group_tips_event(1);
        local rc = uilib:GetControlPtr(ctrl_id):GetRectEx(FALSE,TRUE);
        local p_ctrl = uilib:GetControlPtr(ctrl_id):GetParent();
        local p_id = p_ctrl:GetControlID();
        friend_vlist_node.on_right_button_up(uilib, p_id, rc.left + x, rc.top + y);
    end;

    set_normal_state = function(ctrl_id)
        local bk_id = ui_utility.get_ctrl_id_by_path(ctrl_id, "Ctn_hover");
        if bk_id ~= 0 then
            ui_utility.setproperty_by_id(bk_id, "Background", "");
        end;
    end;

    set_hover_state = function(ctrl_id)
        local bk_id = ui_utility.get_ctrl_id_by_path(ctrl_id, "Ctn_hover");
        ui_utility.setproperty_by_id(bk_id, "Background", "COLOR:RGB:229,229,229;");
        local g_info = friend_vlist_model.virtual_node_id_to_group_info[ctrl_id];
    end;

    set_selected_state = function(ctrl_id, b_select)
        friend_vlist_node.restore_banner_bk();
        local bk_id = ui_utility.get_ctrl_id_by_path(ctrl_id, "Ctn_bk");
        if b_select then
            ui_utility.setproperty_by_id(bk_id, "Background", "COLOR:RGB:229,229,229;");
            friend_vlist_node.set_game_status_online_color(ctrl_id, friend_list_model.GAME_ONLINE_COLOR_SEL);
        else
            ui_utility.setproperty_by_id(bk_id, "Background", "");
            friend_vlist_node.set_game_status_online_color(ctrl_id, friend_list_model.GAME_ONLINE_COLOR);
        end;
    end;

    on_left_button_down_discussion_tree = function(uilib, ctrl_id)
        contact_list_control.clicked_treenode();
        friend_vlist_node.update_tree_direction_flag(ctrl_id, friend_vlist_model.b_discussion_cllapsed_);
    end;

    on_left_button_down_group_tree = function(uilib, ctrl_id)
        contact_list_control.clicked_grouptreenode();
        friend_vlist_node.update_tree_direction_flag(ctrl_id, friend_vlist_model.b_group_cllapsed_);
    end;

    send_hide_group_tips_event = function(action)
        base_utility.log(string.format("[friend_vlist_node]send_hide_group_tips_event:%d", action));
        local param = {};
        param["bShow"] = false;
        param["action"] = action;
        event_center.send_event(group_event.SHOW_FRIEND_TIPS,base_utility.table_to_json(param));
    end;

    --更新箭头方向
    update_tree_direction_flag = function(ctrl_id, is_cllapsed)
        local ui_str, str_hodler = U8toCUIStr("Direction_Flag_Right");
        local id_right = ui_utility.uilib():GetControlIDbyPath(ui_str, ctrl_id);

        local ui_str, str_hodler = U8toCUIStr("Direction_Flag_Down");
        local id_down = ui_utility.uilib():GetControlIDbyPath(ui_str, ctrl_id);

        if is_cllapsed then
            ui_utility.setproperty_by_id(id_right, "Visible", "true");
            ui_utility.setproperty_by_id(id_down, "Visible", "false");
        else
            ui_utility.setproperty_by_id(id_right, "Visible", "false");
            ui_utility.setproperty_by_id(id_down, "Visible", "true");
        end

    end;

};
